package cn.tedu._01mvcboot01.controller;

import cn.tedu._01mvcboot01.pojo.dto.BMIDTO;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class BMIController {
    //    @RequestMapping("/bmi")
    @GetMapping("/bmi")
    @ResponseBody
    public String bmi(BMIDTO bmidto) {
        Double height = bmidto.getHeight();
        Double weight = bmidto.getWeight();
        Double bmi = weight / (height * height);
        String text;
        if (bmi < 18.5) {
            text = "偏瘦";
        } else if (bmi < 24) {
            text = "正常";
        } else if (bmi < 27) {
            text = "微胖";
        } else {
            text = "该减肥了！";
        }
        return "您的身高为：" + height + "m，体重为：" + weight + "kg，BMI指数为：" + bmi + "，您的体形：" + text;
    }

    @GetMapping("/bmi2/{height}/{weight}")
    @ResponseBody
    public String bmi2(@PathVariable Double height,@PathVariable Double weight) {
        Double bmi = weight / (height * height);
        String text;
        if (bmi < 18.5) {
            text = "偏瘦";
        } else if (bmi < 24) {
            text = "正常";
        } else if (bmi < 27) {
            text = "微胖";
        } else {
            text = "该减肥了！";
        }
        return "您的身高为：" + height + "m，体重为：" + weight + "kg，BMI指数为：" + bmi + "，您的体形：" + text;
    }
}
